package com.shujia.mr.scoreSort;

import com.shujia.mr.sortPartition.Student;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ScoreSortMapper extends Mapper<LongWritable, Text, StudentSort, NullWritable> {
    /*
        从ReduceJoin的结果文件中读取数据，对整个学生数据按成绩进行排序，成绩相同按ID排序 写出结果到文件中
     */

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, StudentSort, NullWritable>.Context context) throws IOException, InterruptedException {
//        super.map(key, value, context);


        String oneStu = value.toString();
        String[] split = oneStu.split("\t");
        String id = split[0];
        String[] col = split[1].split(",");
        StudentSort studentSort = new StudentSort(id, col[0], Integer.parseInt(col[1]), col[2], col[3], Integer.parseInt(col[4]));
        context.write(studentSort,NullWritable.get());

    }
}
